DEFINITION MODULE Storage;

(* This is the management module for the Modula-2 heap. *)

FROM SYSTEM IMPORT ADDRESS;

EXPORT QUALIFIED
  ALLOCATE, DEALLOCATE, Available, CreateHeap, DestroyHeap;

PROCEDURE ALLOCATE (VAR addr : ADDRESS; amount : CARDINAL);
 (* allocates the requested amount of memory (in bytes) and returns the *)
 (* starting address . HALT if the amount is not available              *)

PROCEDURE DEALLOCATE (VAR addr : ADDRESS; amount : CARDINAL);
 (* deallocates the given amount of memory (in bytes). HALT if the *)
 (* memory hasn't been allocated by ALLOCATE                       *)

PROCEDURE Available (amount : CARDINAL) : BOOLEAN;
 (* returns TRUE if an ALLOCATE of the specified amount (in bytes) *)
 (* of memory would be possible                                    *)

PROCEDURE CreateHeap (amount : CARDINAL);
 (* reserves an amount for the heap - takes it from the system *)

PROCEDURE DestroyHeap;
  (* releases the heap - is also done automatically at program end *)
END Storage.
